package com.ssms.controller;

import com.ssms.commons.Result;
import com.ssms.commons.TablePage;
import com.ssms.model.Subject;
import com.ssms.service.SubjectService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/subject")
public class SubjectController {

    @Resource
    private SubjectService subjectService;

    @RequestMapping()
    public String subject() {
        return "subject";
    }

    @RequestMapping("list")
    @ResponseBody
    public TablePage list(TablePage tablePage, @RequestParam(value = "searchValue",required = false) String searchValue) {
        return subjectService.search(tablePage, searchValue);
    }

    @RequestMapping("all")
    @ResponseBody
    public Result all() {
        return subjectService.all();
    }

    @RequestMapping("list/academy/{academyId}")
    @ResponseBody
    public Result getByAcademy(@PathVariable("academyId") Integer academyId) {
        return subjectService.getByAcademyId(academyId);
    }

    @RequestMapping("add")
    @ResponseBody
    public Result add(Subject subject) {
        return subjectService.saveSubject(subject);
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(Subject subject) {
        return subjectService.update(subject);
    }

    @RequestMapping("delete")
    @ResponseBody
    public Result delete(Integer id) {
        return subjectService.delete(id);
    }

    @RequestMapping("getInfo")
    @ResponseBody
    public Result getInfo(Integer id) {
        return subjectService.query(id);
    }


}
